package org.jeecg.modules.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.system.entity.BizAlarmEntity;
import org.jeecg.modules.system.entity.BizEquipmentEntity;
import org.jeecg.modules.system.service.IBizAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/biz/alarm")
@Api(tags="告警管理")
public class BizAlarmController {

    @Autowired
    private IBizAlarmService bizAlarmService;

    @ApiOperation(value = "查询未处理数量", notes = "status-告警状态：0. 未确认告警  1.已确认告警  2.已结束告警")
    @RequestMapping(value = "/listAlarmCount", method = RequestMethod.GET)
    public Result<IPage<BizAlarmEntity>> listAlarmCount(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                        @RequestParam(name="pageSize", defaultValue="100000") Integer pageSize,
                                                        @RequestParam(name="siteId",required = false) String siteId,
                                                        @RequestParam(name="eqId",required = false) String eqId,
                                                        @RequestParam(name="startTime",required = false) String startTime,
                                                        @RequestParam(name="endTime",required = false) String endTime,
                                                        @RequestParam(name="status",required = false) String status,HttpServletRequest req) {
        Result<IPage<BizAlarmEntity>> result = new Result<IPage<BizAlarmEntity>>();
        QueryWrapper<BizAlarmEntity> queryWrapper = new QueryWrapper();
        if(StringUtils.isNotEmpty(siteId)){
            queryWrapper.eq("site_id",siteId);
        }

        if(StringUtils.isNotEmpty(eqId)){
            queryWrapper.eq("eq_id",eqId);
        }
        if(StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)){
            queryWrapper.between("begin_Time",startTime,endTime);
            queryWrapper.between("end_Time",startTime,endTime);
        }
        if(StringUtils.isNotEmpty(status)){
            queryWrapper.eq("status",status);
        }

        Page<BizAlarmEntity> page = new Page<BizAlarmEntity>(pageNo, pageSize);
        IPage<BizAlarmEntity> pageList = bizAlarmService.page(page, queryWrapper);

        result.setResult(pageList);
        result.success("查询成功!");
        return result;
    }
}
